package com.geekaca.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


@WebServlet(urlPatterns = "/testParam")
public class ParamServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 接收中文乱码问题
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF8");
        resp.setContentType("text/html;charset=utf-8");
//        Map<String, String[]> parameterMap = req.getParameterMap();
//        parameterMap.forEach((key,strArr)->{
//            System.out.println("key: "+key);
//            System.out.println("values: "+ Arrays.toString(strArr));
//        });
//        String username = req.getParameter("username");
//        System.out.println(username);
//
//        String[] hobbies = req.getParameterValues("hobby");
//        System.out.println(Arrays.toString(hobbies));
        PrintWriter writer = resp.getWriter();

        String s = req.getParameter("s");
        writer.write("用户名: " + s);


    }
}
